<template>
  <div>
    <div class="titleBox">节目排行榜 <span>更多 ></span></div>
    <ul>
      <router-link
        :to="{ name: 'program', query: { id: item.program.id } }"
        tag="li"
        v-for="item in programRankingList"
        :key="item.id"
        class="listItem"
      >
        <img :src="item.program.blurCoverUrl" class="itemImg" alt="" />
        <div class="nameBox">
          <p>{{ item.program.name }}</p>
          <p>{{ item.program.radio.name }}</p>
        </div>
        <p
          class="category"
          v-if="item.program.radio && item.program.radio.category"
        >
          {{ item.program.radio.category }}
        </p>
      </router-link>
    </ul>
  </div>
</template>

<script>
import { programRanking } from "@/api";
export default {
  props: {
    limit: {
      type: Number,
      default: 10,
    },
  },
  data() {
    return {
      programRankingList: [],
    };
  },
  created() {
    this.getprogramRanking();
  },
  methods: {
    //推荐排行
    getprogramRanking() {
      programRanking({ limit: this.limit }).then((res) => {
        // console.log(res.toplist);
        this.programRankingList = res.toplist;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.titleBox {
  height: 40px;
  border-bottom: 2px solid #c20c0c;
  font-size: 24px;
  color: #333;
  span {
    float: right;
    font-size: 12px;
    margin-top: 14px;
    color: #666;
    cursor: pointer;
  }
}
.listItem {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  .itemImg {
    width: 40px;
    height: 40px;
    margin-right: 10px;
  }
  .nameBox {
    flex: 1;
    overflow: hidden;
    p {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: #333;
      line-height: 20px;
      &:nth-child(2) {
        color: #999;
      }
    }
  }
  .category {
    display: inline-block;
    height: 16px;
    overflow: hidden;
    padding: 0 6px;
    border: 1px solid #999;
    line-height: 16px;
    color: #999;
    vertical-align: middle;
    font-size: 12px;
  }
  &:nth-of-type(even) {
    background: #f7f7f7;
  }
  &:hover {
    background: #eee;
  }
}
</style>